home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Network Support Library
/
RoseWare - Network Support Library.iso
/
apidev
/
mhs_c.arc
/
OUTPOST.ARC
/
COMMANDS.C
< prev
next >
Wrap
C/C++ Source or Header
|
1988-06-27
|
6KB
|
233 lines
/* ****************************** COMMANDS.C ****************************** */
#include "cctypes.h"
/*
The bits in the Month-Day-Year byte are defined as follows:
YYYYYYY MMMM DDDDD
*/
#define GetMonth(x) (((x) >> 5) & 0x0F)
#define GetDay(x) ((x) & 0x1F)
#define GetYear(x) ((((x) >> 9) & 0x7F) + 80)
/*
The bits in the Hour-Minute byte are defined as follows:
HHHHH MMMMMM
*/
#define GetHour(x) (((x) >> 11) & 0x1F)
#define GetMinute(x) (((x) >> 5) & 0x3F)
#define FIRST_WORD_SIZE 37
/* extern char Out[]; */
extern char currentLine[];
extern int ErrorsInThisFile;
extern int warningFound;
extern int lineNumber;
extern int OutFile;
extern int InFile;
extern int contentsWritten;
/* extern MCB MCBStruct; */
extern char messageBuffer[];
extern char workArea[];
extern XRB XRBRec[];
extern void AddCurrentLineToMessageBuffer();
extern int GetNextLine();
extern void GetFirstWord();
extern void BlankLine();
extern void WriteIt();
void WriteAttachmentFile();
int CreateXRBLine(type)
int type;
{
int returnCode = NO_ERROR, ccode = 0, bytes, i;
char fileName[81], temp1[60], temp2[60], *p, *p2;
char firstWord[FIRST_WORD_SIZE];
static int inMessage = 0;
static int inTextItem = 0;
static int hasAttachment = 0;
extern void InitMCB();
/* Out[0] = '\0'; */
warningFound = 0;
switch ( type ) {
case DATE:
WriteIt(currentLine);
BlankLine();
break;
case FROM:
p = stptok(¤tLine[6], temp1, sizeof(temp1), " ");
p2 = stptok(p+2, temp2, sizeof(temp2), " ");
sprintf(temp2, "From: %s at %s", temp1, p2);
WriteIt(temp2);
BlankLine();
break;
case TO:
p = stptok(¤tLine[4], temp1, sizeof(temp1), " ");
p2 = stptok(p+2, temp2, sizeof(temp2), " ");
sprintf(temp2, "To: %s at %s", temp1, p2);
WriteIt(temp2);
BlankLine();
break;
case MESSAGE_ID:
/* AddCurrentLineToMessageBuffer(); */
break;
case CONVERSATION_ID:
/* AddCurrentLineToMessageBuffer(); */
break;
case VIA_HOST:
/* AddCurrentLineToMessageBuffer(); */
break;
case SUBJECT:
WriteIt(currentLine);
BlankLine();
break;
case MESSAGE_TYPE:
/* AddCurrentLineToMessageBuffer(); */
break;
case COPIES_TO:
/* STUB */
AddCurrentLineToMessageBuffer();
break;
case RE_SENT_BY:
/* STUB */
AddCurrentLineToMessageBuffer();
break;
case RESPOND_BY:
/* AddCurrentLineToMessageBuffer(); */
break;
case POSSIBILITY:
/* AddCurrentLineToMessageBuffer(); */
break;
case ACTION:
p = stptok(¤tLine[8], temp1, sizeof(temp1), "\12\15");
sprintf(temp2, "Subject: %s", temp1);
WriteIt(temp2);
BlankLine();
break;
case RET_MESSAGE:
/* AddCurrentLineToMessageBuffer(); */
break;
case IN_REPLY_TO:
/* AddCurrentLineToMessageBuffer(); */
break;
case FORM:
/* AddCurrentLineToMessageBuffer(); */
break;
case DOMAIN:
/* AddCurrentLineToMessageBuffer(); */
break;
case COMPLETE_BY:
/* AddCurrentLineToMessageBuffer(); */
break;
case NEW_COMPLETE_BY:
/* AddCurrentLineToMessageBuffer(); */
break;
case ATTACHMENT:
/* STUB save the name(s) of any attachment files and append them last */
i=17; /* offset into current line to get the filename */
goto NetAttach;
break;
case NET_ATTACHMENT:
i=16; /* offset into current line to get the filename */
/* STUB save the name(s) of any attachment files and append them last */
NetAttach:
if ( !contentsWritten ) {
contentsWritten++;
WriteIt("Contents:");
BlankLine();
}
/* get original fileName */
p = stptok(¤tLine[i], temp1, sizeof(temp1), " \12\15");
/* ...and strip off just the file node name */
temp2[0] = '\0';
stcgfn(temp2, temp1);
WriteAttachmentFile(temp2); /* pass in original name */
break;
default:
;
}
return(returnCode);
}
/* copies the attachment file right into the CC:MAIL file to be imported */
void WriteAttachmentFile(originalName)
char *originalName;
{
int inHandle, bytesRead, temp = 0, ccode;
char *buffer, inName[80], tsize[10], searchAttributes, command[256];
int month, day, year, hour, minute;
char ampm;
unsigned t;
long fSize, fileSize = 0L;
FILEINFO fileInfo;
buffer = (char *)(malloc(30000)); /* allocate statically ? */
if ( buffer == (char *)NULL )
return;
/* get the OPARCEL filname */
/* ********* open OPARCEL file ********** */
sprintf(inName, "Q:OPARCEL\\%s",XRBRec[4].t);
ccode = FindFirstFile(inName, &fileInfo, (char)0);
if ( ccode ) goto Out; /* file not found */
t = fileInfo.fileDate;
month = GetMonth(t);
day = GetDay(t);
year = GetYear(t);
t = fileInfo.fileTime;
hour = GetHour(t);
minute = GetMinute(t);
if ( hour >= 12 )
ampm = 'p';
else
ampm = 'a';
if ( hour > 12 )
hour -= 12;
/* STUB should be opened for exclusive access */
inHandle = open(inName, O_RDONLY | O_RAW, 0); /* open the OPARCEL file for read */
if ( inHandle == -1 )
goto Out;
/* *********** write "File item: <filename>" ********** */
sprintf(command, "File item: %s %d/%d/%d %d:%d%cm", originalName,
month, day, year, hour, minute, ampm); /* preserve the original filename */
WriteIt(command);
BlankLine();
fSize = lseek(inHandle, 0L, 2);
sprintf(tsize, "%ld", fSize);
/* ******** write out the file size ********** */
WriteIt(tsize);
BlankLine();
lseek(inHandle, 0L, 0); /* reset the file pointer */
while ( fSize > 0 ) {
temp = fSize < 30000 ? fSize : 30000;
bytesRead = read(inHandle, buffer, temp);
if ( bytesRead )
write(OutFile, buffer, bytesRead);
fSize -= bytesRead;
fileSize += bytesRead;
}
close(inHandle);
unlink(inName);
Out:
free(buffer);
}